package com.wz.controller;

import com.wz.pojo.Department;
import com.wz.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collection;

@Controller
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;

    /**显示部门全部信息*/
    @RequestMapping("/list")
    public String  getAllDept(Model model){
        Collection<Department> departmentCollection =departmentService.AllDepartment();
        //System.out.println("后台信息："+departmentCollection);
        model.addAttribute("depts",departmentCollection);
        return "dept/list";
    }


    /**去添加部门页面*/
    @RequestMapping("/toAddDept")
    public String toAddDpet(){
        return "dept/add";
    }

    /**添加部门*/
    @PostMapping("/addDept")
    public String addDept(Department department){
        departmentService.addDept(department);
        return "redirect:/list";
    }




}
